﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QFlow.Data
{
    public partial class PurchaseItem
    {
        bool _IsDirty;

        public PurchaseItem Clone()
        {
            return new PurchaseItem
            {
                DiscountPercent = this.DiscountPercent,
                ExpirationDate = this.ExpirationDate,
                ItemType = this.ItemType,
                Notes = this.Notes,
                Product = this.Product,
                Quantity = this.Quantity,
                TaxesPercent = this.TaxesPercent,
                UnitPrice = this.UnitPrice,
                User = this.User,
                VendorCode = this.VendorCode,
                ParentPurchaseItemID = this.ParentPurchaseItemID
            };
        }

        public bool IsAttached()
        {
            return this.PurchaseItemID != 0;
        }

        public bool IsDirty()
        {
            return _IsDirty;
        }

        partial void OnLoaded()
        {
            if (PropertyChanged == null)
                PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(PurchaseItem_PropertyChanged);
        }

        partial void OnCreated()
        {
            if (PropertyChanged == null)
                PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(PurchaseItem_PropertyChanged);
        }

        void PurchaseItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            _IsDirty = true;
        }

        public override string ToString()
        {
            return this.ExpirationDate.ToString("dd-MM-yyyy");
        }
    }
}
